package com.example.topguli;

import java.util.concurrent.locks.ReentrantLock;

public class ReentryLockTest {
    private  ReentrantLock reentrantLock = new ReentrantLock();
    public static void main(String[] args) {
        ReentryLockTest reentryLockTest = new ReentryLockTest();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                reentryLockTest.A();
            }).start();
        }
    }
    public void A(){
        reentrantLock.lock();
        try {
            System.out.println("业务A");
            System.out.println("业务B准备执行");
            this.B();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            reentrantLock.unlock();
        }
    }

    public void B(){
        reentrantLock.lock();
        try {
            System.out.println("业务B执行");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
         reentrantLock.unlock();
        }
    }

}
